package com.xbongbong.paas.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.xbongbong.paas.pojo.dto.ReportTargetEnableDTO;
import com.xbongbong.paas.pojo.vo.ReportTargetVO;
import com.xbongbong.paas.redis.PaasRedisHelper;
import com.xbongbong.paas.service.CompanyConfigService;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.BaseDTO;
import com.xbongbong.paas.toolbox.wrap.BaseVO;
import com.xbongbong.paas.toolbox.wrap.XbbResponse;
import com.xbongbong.pro.companyconfig.pojo.dto.CompanyConfigAddDTO;
import com.xbongbong.pro.companyconfig.pojo.dto.CompanyConfigEnableDTO;
import com.xbongbong.pro.companyconfig.pojo.dto.CompanyConfigFindDTO;
import com.xbongbong.pro.companyconfig.pojo.dto.CompanyConfigGetFiscalDTO;
import com.xbongbong.pro.companyconfig.pojo.dto.CompanyConfigGetJxcConfigDTO;
import com.xbongbong.pro.companyconfig.pojo.dto.CompanyConfigGetPerformanceFinishDTO;
import com.xbongbong.pro.companyconfig.pojo.dto.CompanyConfigGetPerformanceLeaveDTO;
import com.xbongbong.pro.companyconfig.pojo.dto.CompanyConfigGetWorkingDayMonthDTO;
import com.xbongbong.pro.companyconfig.pojo.dto.CompanyConfigGetWorkingDayWeekDTO;
import com.xbongbong.pro.companyconfig.pojo.dto.CompanyConfigHasBeenEnableBatchDTO;
import com.xbongbong.pro.companyconfig.pojo.dto.CompanyConfigHasBeenEnableDTO;
import com.xbongbong.pro.companyconfig.pojo.dto.CompanyConfigHasBeenSetDTO;
import com.xbongbong.pro.companyconfig.pojo.dto.CompanyConfigRaidersWhiteDTO;
import com.xbongbong.pro.companyconfig.pojo.dto.CompanyConfigSetFiscalDTO;
import com.xbongbong.pro.companyconfig.pojo.dto.CompanyConfigSetPerformanceFinishDTO;
import com.xbongbong.pro.companyconfig.pojo.dto.CompanyConfigSetWorkingDayMonthDTO;
import com.xbongbong.pro.companyconfig.pojo.dto.CompanyConfigSetWorkingDayWeekDTO;
import com.xbongbong.pro.companyconfig.pojo.dto.CompanyConfigSetWorkrecordDTO;
import com.xbongbong.pro.companyconfig.pojo.vo.CompanyConfigEnableVO;
import com.xbongbong.pro.companyconfig.pojo.vo.CompanyConfigFindVO;
import com.xbongbong.pro.companyconfig.pojo.vo.CompanyConfigGetFiscalVO;
import com.xbongbong.pro.companyconfig.pojo.vo.CompanyConfigGetPerformanceFinishVO;
import com.xbongbong.pro.companyconfig.pojo.vo.CompanyConfigGetPerformanceLeaveVO;
import com.xbongbong.pro.companyconfig.pojo.vo.CompanyConfigGetWorkingDayMonthVO;
import com.xbongbong.pro.companyconfig.pojo.vo.CompanyConfigGetWorkingDayWeekVO;
import com.xbongbong.pro.companyconfig.pojo.vo.CompanyConfigHasBeenEnableBatchVO;
import com.xbongbong.pro.companyconfig.pojo.vo.CompanyConfigHasBeenEnableVO;
import com.xbongbong.pro.companyconfig.pojo.vo.CompanyConfigHasBeenSetVO;
import com.xbongbong.pro.companyconfig.pojo.vo.CompanyConfigJxcConfigVO;
import com.xbongbong.pro.companyconfig.pojo.vo.CompanyConfigRaidersWhiteVO;
import com.xbongbong.pro.companyconfig.pojo.vo.CompanyConfigSetFiscalVO;
import com.xbongbong.pro.companyconfig.pojo.vo.CompanyConfigSetPerformanceFinishVO;
import com.xbongbong.pro.companyconfig.pojo.vo.CompanyConfigSetWorkingDayMonthVO;
import com.xbongbong.pro.companyconfig.pojo.vo.CompanyConfigSetWorkingDayWeekVO;
import com.xbongbong.pro.companyconfig.pojo.vo.CompanyConfigSetWorkrecordVO;
import com.xbongbong.pro.companyconfig.pojo.vo.CompanyConfigValueSetWorkrecordVO;
import com.xbongbong.pro.companyconfig.pojo.vo.JXCSetListVO;
import com.xbongbong.pro.constant.XbbProConstant;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.form.pojo.vo.CustomerCheckSetConfigGetVO;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Objects;

/**
 * @description: 公司配置
 * @Author: hongxiao
 * @date: 2019-01-21 16:01
 */
@RestController
@RequestMapping(XbbProConstant.API_ROOT_PREFIX + "/companyConfig")
public class CompanyConfigController {

    @Resource
    private CompanyConfigService companyConfigService;
    @Resource
    private PaasRedisHelper paasRedisHelper;

    /**
     * 启用/关闭配置（开关类公司配置）
     *
     * @param companyConfigEnableDTO 入参
     * @param br
     * @return
     */
    @RequestMapping(value = "/enable", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String enable(@RequestBody @Valid CompanyConfigEnableDTO companyConfigEnableDTO, BindingResult br) {
        XbbResponse<CompanyConfigEnableVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(companyConfigEnableDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(companyConfigEnableDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                CompanyConfigEnableVO companyConfigEnableVO = companyConfigService.enable(companyConfigEnableDTO);
                response = new XbbResponse<>(companyConfigEnableVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 启用/关闭配置（开关类公司配置）
     *
     * @param companyConfigEnableDTO 入参
     * @param br
     * @return
     */
    @RequestMapping(value = "/enableJxcConfig", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String enableJxcConfig(@RequestBody @Valid CompanyConfigEnableDTO companyConfigEnableDTO, BindingResult br) {
        XbbResponse<CompanyConfigEnableVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(companyConfigEnableDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(companyConfigEnableDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                CompanyConfigEnableVO companyConfigEnableVO = companyConfigService.enableJxcConfig(companyConfigEnableDTO);
                response = new XbbResponse<>(companyConfigEnableVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }
    /**
     * 获取某个规则是否已经存在
     *
     * @param hasBeenSetDTO 入参
     * @param br
     * @return
     * @throws
     * @author hongxiao
     * @date: 2019-02-17 22:03
     * @version v1.0
     * @since v1.0
     */
    @RequestMapping(value = "/hasBeenSet", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String hasBeenSet(@RequestBody @Valid CompanyConfigHasBeenSetDTO hasBeenSetDTO, BindingResult br) {
        XbbResponse<CompanyConfigHasBeenSetVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                CompanyConfigHasBeenSetVO hasBeenSetVO = companyConfigService.hasBeenSet(hasBeenSetDTO);
                response = new XbbResponse<>(hasBeenSetVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 获取规则是否启用
     *
     * @param hasBeenEnableDTO 入参
     * @param br
     * @return
     * @throws
     * @author hongxiao
     * @date: 2019-02-17 22:03
     * @version v1.0
     * @since v1.0
     */
    @RequestMapping(value = "/hasBeenEnable", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String hasBeenEnable(@RequestBody @Valid CompanyConfigHasBeenEnableDTO hasBeenEnableDTO, BindingResult br) {
        XbbResponse<CompanyConfigHasBeenEnableVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                CompanyConfigHasBeenEnableVO hasBeenEnableVO = companyConfigService.hasBeenEnable(hasBeenEnableDTO);
                response = new XbbResponse<>(hasBeenEnableVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 批量获取规则是否启用
     *
     * @param hasBeenEnableBatchDTO 入参
     * @param br
     * @return
     * @throws
     * @author hongxiao
     * @date: 2019-02-17 22:04
     * @version v1.0
     * @since v1.0
     */
    @RequestMapping(value = "/hasBeenEnableBatch", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String hasBeenEnableBatch(@RequestBody @Valid CompanyConfigHasBeenEnableBatchDTO hasBeenEnableBatchDTO, BindingResult br) {
        XbbResponse<CompanyConfigHasBeenEnableBatchVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                CompanyConfigHasBeenEnableBatchVO hasBeenEnableBatchVO = companyConfigService.hasBeenEnableBatch(hasBeenEnableBatchDTO);
                response = new XbbResponse<>(hasBeenEnableBatchVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }
    /**
     * 获取jxc是否启用
     *
     * @param companyConfigGetJxcConfigDTO 入参
     * @param br
     * @return
     * @throws
     * @author hongxiao
     * @date: 2019-02-17 22:04
     * @version v1.0
     * @since v1.0
     */
    @RequestMapping(value = "/getJxcConfig", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getJxcConfig(@RequestBody @Valid CompanyConfigGetJxcConfigDTO companyConfigGetJxcConfigDTO, BindingResult br) {
        XbbResponse<CompanyConfigJxcConfigVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                CompanyConfigJxcConfigVO companyConfigJxcConfigVO = companyConfigService.getJxcConfig(companyConfigGetJxcConfigDTO);
                response = new XbbResponse<>(companyConfigJxcConfigVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 获取公司财年配置
     * @param companyConfigGetFiscalDTO 入参
     * @param br
     * @return
     * @throws
     *
     * @author hongxiao
     * @date: 2019-02-17 16:45
     * @since v1.0
     * @version v1.0
     */
    @RequestMapping(value = "/getFiscal", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getFiscal(@RequestBody @Valid CompanyConfigGetFiscalDTO companyConfigGetFiscalDTO, BindingResult br) {
        XbbResponse<CompanyConfigGetFiscalVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                CompanyConfigGetFiscalVO companyConfigGetFiscalVO = companyConfigService.getFiscal(companyConfigGetFiscalDTO);
                response = new XbbResponse<>(companyConfigGetFiscalVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 配置公司财年
     * @param companyConfigSetFiscalDTO 入参
     * @param br
     * @return
     * @throws
     *
     * @author hongxiao
     * @date: 2019-02-17 17:07
     * @since v1.0
     * @version v1.0
     */
    @RequestMapping(value = "/setFiscal", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String setFiscal(@RequestBody @Valid CompanyConfigSetFiscalDTO companyConfigSetFiscalDTO, BindingResult br) {
        XbbResponse<CompanyConfigSetFiscalVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(companyConfigSetFiscalDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(companyConfigSetFiscalDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                CompanyConfigSetFiscalVO companyConfigSetFiscalVO = companyConfigService.setFiscal(companyConfigSetFiscalDTO);
                response = new XbbResponse<>(companyConfigSetFiscalVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 获取每月工作日天数
     * @param getWorkingDayMonthDTO 入参
     * @param br
     * @return
     * @throws
     *
     * @author hongxiao
     * @date: 2019-02-17 19:42
     * @since v1.0
     * @version v1.0
     */
    @RequestMapping(value = "/getWorkingDayMonth", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getWorkingDayMonth(@RequestBody @Valid CompanyConfigGetWorkingDayMonthDTO getWorkingDayMonthDTO, BindingResult br) {
        XbbResponse<CompanyConfigGetWorkingDayMonthVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                CompanyConfigGetWorkingDayMonthVO getWorkingDayMonthVO = companyConfigService.getWorkingDayMonth(getWorkingDayMonthDTO);
                response = new XbbResponse<>(getWorkingDayMonthVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 设置每月工作日天数
     * @param setWorkingDayMonthDTO 入参
     * @param br
     * @return
     * @throws
     *
     * @author hongxiao
     * @date: 2019-02-17 19:42
     * @since v1.0
     * @version v1.0
     */
    @RequestMapping(value = "/setWorkingDayMonth", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String setWorkingDayMonth(@RequestBody @Valid CompanyConfigSetWorkingDayMonthDTO setWorkingDayMonthDTO, BindingResult br) {
        XbbResponse<CompanyConfigSetWorkingDayMonthVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(setWorkingDayMonthDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(setWorkingDayMonthDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                CompanyConfigSetWorkingDayMonthVO setWorkingDayMonthVO = companyConfigService.setWorkingDayMonth(setWorkingDayMonthDTO);
                response = new XbbResponse<>(setWorkingDayMonthVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 获取每周工作日天数
     * @param getWorkingDayWeekDTO 入参
     * @param br
     * @return
     * @throws
     *
     * @author hongxiao
     * @date: 2019-02-17 19:43
     * @since v1.0
     * @version v1.0
     */
    @RequestMapping(value = "/getWorkingDayWeek", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getWorkingDayWeek(@RequestBody @Valid CompanyConfigGetWorkingDayWeekDTO getWorkingDayWeekDTO, BindingResult br) {
        XbbResponse<CompanyConfigGetWorkingDayWeekVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                CompanyConfigGetWorkingDayWeekVO getWorkingDayWeekVO = companyConfigService.getWorkingDayWeek(getWorkingDayWeekDTO);
                response = new XbbResponse<>(getWorkingDayWeekVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 设置每周工作日天数
     * @param setWorkingDayWeekDTO 入参
     * @param br
     * @return
     * @throws
     *
     * @author hongxiao
     * @date: 2019-02-17 19:43
     * @since v1.0
     * @version v1.0
     */
    @RequestMapping(value = "/setWorkingDayWeek", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String setWorkingDayMonth(@RequestBody @Valid CompanyConfigSetWorkingDayWeekDTO setWorkingDayWeekDTO, BindingResult br) {
        XbbResponse<CompanyConfigSetWorkingDayWeekVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(setWorkingDayWeekDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(setWorkingDayWeekDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                CompanyConfigSetWorkingDayWeekVO setWorkingDayWeekVO = companyConfigService.setWorkingDayWeek(setWorkingDayWeekDTO);
                response = new XbbResponse<>(setWorkingDayWeekVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 获取Web端完成情况中完成率颜色标识
     * @param getPerformanceFinishDTO 入参
     * @param br
     * @return
     * @throws
     *
     * @author hongxiao
     * @date: 2019-02-17 19:44
     * @since v1.0
     * @version v1.0
     */
    @RequestMapping(value = "/getPerformanceFinish", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getPerformanceFinish(@RequestBody @Valid CompanyConfigGetPerformanceFinishDTO getPerformanceFinishDTO, BindingResult br) {
        XbbResponse<CompanyConfigGetPerformanceFinishVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                CompanyConfigGetPerformanceFinishVO getPerformanceFinishVO = companyConfigService.getPerformanceFinish(getPerformanceFinishDTO);
                response = new XbbResponse<>(getPerformanceFinishVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 获取简报指标设置
     *
     * @param baseDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/getReportTarget", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getReportTarget(@RequestBody @Valid BaseDTO baseDTO, BindingResult br) {
        XbbResponse<ReportTargetVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                ReportTargetVO reportTargetVO = companyConfigService.getReportTarget(baseDTO);
                response = new XbbResponse<>(reportTargetVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 设置Web端完成情况中完成率颜色标识
     * @param setPerformanceFinishDTO 入参
     * @param br
     * @return
     * @throws
     *
     * @author hongxiao
     * @date: 2019-02-17 19:44
     * @since v1.0
     * @version v1.0
     */
    @RequestMapping(value = "/setPerformanceFinish", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String setPerformanceFinish(@RequestBody @Valid CompanyConfigSetPerformanceFinishDTO setPerformanceFinishDTO, BindingResult br) {
        XbbResponse<CompanyConfigSetPerformanceFinishVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(setPerformanceFinishDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(setPerformanceFinishDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                CompanyConfigSetPerformanceFinishVO setPerformanceFinishVO = companyConfigService.setPerformanceFinish(setPerformanceFinishDTO);
                response = new XbbResponse<>(setPerformanceFinishVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 开启、关闭简报指标
     *
     * @param reportTargetEnableDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/enableReportTarget", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String enableReportTarget(@RequestBody @Valid ReportTargetEnableDTO reportTargetEnableDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                BaseVO baseVO = companyConfigService.enableReportTarget(reportTargetEnableDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 获取配置（开关类公司配置）
     *
     * @param baseDTO 入参
     * @param br
     * @return
     */
    @RequestMapping(value = "/customerCheckSet/get", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getCustomerCheckSet(@RequestBody @Valid BaseDTO baseDTO, BindingResult br) {
        XbbResponse<CustomerCheckSetConfigGetVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                CustomerCheckSetConfigGetVO customerCheckSetConfigGetVO = companyConfigService.getCustomerCheckSet(baseDTO);
                response = new XbbResponse<>(customerCheckSetConfigGetVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

//    /**
//     * 启用/关闭配置（开关类公司配置）
//     *
//     * @param companyConfigEnableDTO 入参
//     * @param br
//     * @return
//     */
//    @RequestMapping(value = "/customerCheckSet/enable", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public String enableCustomerCheckSet(@RequestBody @Valid CompanyConfigEnableDTO companyConfigEnableDTO, BindingResult br) {
//        XbbResponse<CustomerCheckSetConfigGetVO> response;
//        if (br.hasErrors()) {
//            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
//            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
//        } else {
//            try {
//                CustomerCheckSetConfigGetVO customerCheckSetConfigGetVO = companyConfigService.enableCustomerCheckSet(companyConfigEnableDTO);
//                response = new XbbResponse<>(customerCheckSetConfigGetVO);
//            } catch (XbbException e) {
//                response = new XbbResponse<>(e);
//            }
//        }
//        return JSON.toJSONString(response);
//    }

    /**
     * 获取钉钉待办配置
     * @param baseDTO
     * @param br
     * @return
     * @throws
     * @author xingxing.xiao
     * @date 2019/08/02 10:24
     */
    @RequestMapping(value = "/dintalkWorkrecordConfig/get", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getDintalkWorkrecordConfig(@RequestBody @Valid BaseDTO baseDTO, BindingResult br) {
        XbbResponse<CompanyConfigSetWorkrecordVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                CompanyConfigSetWorkrecordVO companyConfigSetWorkrecordVO = companyConfigService.getDintalkWorkrecordConfig(baseDTO);
                response = new XbbResponse<>(companyConfigSetWorkrecordVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 同步钉钉待办开启/关闭
     * @param companyConfigSetWorkrecordDTO
     * @param br
     * @return
     * @throws
     * @author xingxing.xiao
     * @date 2019/08/02 10:24
     */
    @RequestMapping(value = "/dintalkWorkrecordConfig/set", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String setDintalkWorkrecordConfig(@RequestBody @Valid CompanyConfigSetWorkrecordDTO companyConfigSetWorkrecordDTO, BindingResult br) {
        XbbResponse<CompanyConfigValueSetWorkrecordVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(companyConfigSetWorkrecordDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(companyConfigSetWorkrecordDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                CompanyConfigValueSetWorkrecordVO companyConfigValueSetWorkrecordVO = companyConfigService.setDintalkWorkrecordConfig(companyConfigSetWorkrecordDTO);
                response = new XbbResponse<>(companyConfigValueSetWorkrecordVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 价值攻略白名单设置
     * @param companyConfigRaidersWhiteDTO
     * @param br
     * @return java.lang.String
     * @author zcp
     * @date 19/10/14 014 17:28
     * @update 19/10/14 014 17:28
     * @since v1.0
     * @version v1.0
     */
    @RequestMapping(value = "/setRaidersWhite", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String setRaidersWhite(@RequestBody @Valid CompanyConfigRaidersWhiteDTO companyConfigRaidersWhiteDTO, BindingResult br) {
        XbbResponse<CompanyConfigRaidersWhiteVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(companyConfigRaidersWhiteDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(companyConfigRaidersWhiteDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                CompanyConfigRaidersWhiteVO companyConfigRaidersWhiteVO = companyConfigService.setRaidersWhite(companyConfigRaidersWhiteDTO);
                response = new XbbResponse<>(companyConfigRaidersWhiteVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取Web端业绩指标离职显示
     * @param companyConfigGetPerformanceLeaveDTO
     * @param br
     * @return java.lang.String
     * @throws XbbException
     * @author xinpeng.jiang
     * @date 2021/8/26 17:27
     * @version 1.0
     */
    @RequestMapping(value = "/getPerformanceLeave", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getPerformanceLeave(@RequestBody @Valid CompanyConfigGetPerformanceLeaveDTO companyConfigGetPerformanceLeaveDTO, BindingResult br) {
        XbbResponse<CompanyConfigGetPerformanceLeaveVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                CompanyConfigGetPerformanceLeaveVO companyConfigGetPerformanceLeaveVO = companyConfigService.getPerformanceLeave(companyConfigGetPerformanceLeaveDTO);
                response = new XbbResponse<>(companyConfigGetPerformanceLeaveVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 保存公司配置
     *
     * @param companyConfigAddDTO 保存公司配置
     * @param br                  br
     * @return CompanyConfigAddBatchVO
     */
    @RequestMapping(value = "/aliyunCallcentersave", method = RequestMethod.POST)
    public String aliyunCallcentersave(@RequestBody @Valid CompanyConfigAddDTO companyConfigAddDTO, BindingResult br) {
        XbbResponse<Integer> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                Integer save = companyConfigService.aliyunCallcentersave(companyConfigAddDTO);
                response = new XbbResponse<>(save);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }
    /**
     * 查询公司配置
     *
     * @param findDTO 保存公司配置
     * @param br                  br
     * @return CompanyConfigAddBatchVO
     */
    @RequestMapping(value = "/find", method = RequestMethod.POST)
    public String findCompanyConfig(@RequestBody @Valid CompanyConfigFindDTO findDTO, BindingResult br) {
        XbbResponse<CompanyConfigFindVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                CompanyConfigFindVO companyConfig = companyConfigService.findCompanyConfig(findDTO);
                response = new XbbResponse<>(companyConfig);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    @RequestMapping(value = "/getJxcConfigList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getJxcConfigList(@RequestBody @Valid CompanyConfigGetJxcConfigDTO companyConfigGetJxcConfigDTO, BindingResult br) {
        XbbResponse<JXCSetListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                JXCSetListVO jxcSetListVO = companyConfigService.getJxcConfigList(companyConfigGetJxcConfigDTO);
                response = new XbbResponse<>(jxcSetListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

}
